import request from '@/utils/request'

export function getChallengeInProgress () {
  return request({
    url: '/challengeInProgress',
    method: 'post'
  })
}

export function getChallengeEnded () {
  return request({
    url: '/challengeEnded',
    method: 'post'
  })
}

export function getChallengeInProgressUser (userId: number) {
  return request({
    url: '/challengeInProgressUser',
    method: 'post',
    params: {
      userId
    }
  })
}

export function getChallengeEndedUser (userId: number) {
  return request({
    url: '/challengeEndedUser',
    method: 'post',
    params: {
      userId
    }
  })
}

export function launchChallenge (challengeName: string, startTime: string, endTime: string, stockCode: string, startingFunds: number, maxParticipantsNumber: number, introduction: string) {
  return request({
    url: '/launchChallenge',
    method: 'post',
    data: {
      challengeName,
      startTime,
      endTime,
      stockCode,
      startingFunds,
      maxParticipantsNumber,
      introduction
    }
  })
}

export function signForChallenge (challengeId: number, userId: number, conditionSheetId: string) {
  return request({
    url: '/signForChallenge',
    method: 'post',
    params: {
      challengeId,
      userId,
      conditionSheetId
    }
  })
}

export function realTimeRanking (challengeId: number) {
  return request({
    url: '/realTimeRanking',
    method: 'post',
    params: {
      challengeId
    }
  })
}

export function getChallengeInfo (challengeId: number) {
  return request({
    url: '/getChallengeInfo',
    method: 'post',
    params: {
      challengeId
    }
  })
}

export function compete (challengeId: number, userId: number) {
  return request({
    url: '/compete',
    method: 'post',
    params: {
      challengeId,
      userId
    }
  })
}
